package com.qiaomeng.flutter.flutter_jpush_vip;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import org.json.JSONException;
import org.json.JSONObject;

import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;

public class XReceiver extends JPushMessageReceiver {
    @Override
    public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
        String msgId = notificationMessage.msgId;
        String title = notificationMessage.notificationTitle;
        String content = notificationMessage.notificationContent;
        String extras = notificationMessage.notificationExtras;
        int platform = notificationMessage.platform;
        JSONObject json = new JSONObject();
        try {
            json.put("msg_id", msgId);
            json.put("n_title", title);
            json.put("n_content", content);
            json.put("n_extras", new JSONObject(extras));
            json.put("rom_type", platform);
        } catch (JSONException e) {
            e.printStackTrace();
        }
//        intent.getExtras().getString
        String jpush = json.toString();
        Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getApplicationContext().getPackageName());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        Bundle bundle = new Bundle();
        bundle.putString("JMessageExtra", jpush);
        i.putExtras(bundle);
        context.startActivity(i);
    }


}
